import java.awt.Color;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextPane;

import com.conn.DbCES;
import com.services.CESDate;


public class SwitchDate {

	private final class ButtonListener extends MouseAdapter {
		@Override
		public void mouseClicked(MouseEvent e) {
			JButton button = (JButton)e.getSource();
			if (date.getText() == null 
					|| "".equals(date.getText())) {
				date.setText(CESDate.getSysDate(button.getName()));
			} else {
				text.setText(CESDate.swithDate(date.getText(),
						DbCES.getConnection(button.getName())));
			}
		}
	}

	private JFrame frame;
	JTextPane date = new JTextPane();
	JLabel text = new JLabel();
	
	private static SwitchDate sd = new SwitchDate();

	/**
	 * Create the application.
	 */
	private SwitchDate() {
		this.frame = new JFrame();
		initialize();
	}
	
	public static void show() {
		sd.frame.setVisible(true);
	}
	
	public static void hide() {
		sd.frame.setVisible(false);
	}

	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {
		frame.setBounds(300, 100, 499, 349);
		frame.getContentPane().setLayout(null);
		
        createButton();
        createText();
        
		frame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
		frame.setVisible(false);
	}

	/**
	 * 
	 */
	private void createText() {
		date.setBounds(179, 82, 127, 30);
        frame.getContentPane().add(date);
        
        JLabel dateLabel = new JLabel("修改后日期");
        dateLabel.setBounds(64, 82, 105, 30);
        frame.getContentPane().add(dateLabel);
        text.setForeground(Color.RED);
        
        text.setBounds(64, 122, 358, 88);
        frame.getContentPane().add(text);
	}

	/**
	 * 
	 */
	private void createButton() {
		ButtonListener listener = new ButtonListener();
		JButton button1 = new JButton("STG1环境");
		button1.setName("STG1");
        button1.addMouseListener(new ButtonListener());
        JButton button3 = new JButton("STG3环境");
        button3.setName("STG3");
        button3.addMouseListener(listener);
        button1.setBounds(64, 220, 149, 30);
        button3.setBounds(268, 220, 157, 30);
        frame.getContentPane().add(button1);
        frame.getContentPane().add(button3);
	}
	
	
}
